home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / fm_ext.zip / MY_FMEXT.C < prev    next >
C/C++ Source or Header  |  1992-11-04  |  5KB  |  178 lines

  1. // A simple DLL for File Manager Extentions.
  2. // Build for Windows NT build .340 (October 92 SDK release).
  3. //
  4. // Note: you must export FMExtentionProc from your .def file.  You
  5. // list this DLL as a File Manager extention by adding a line in
  6. // your ...\NT\winfile.ini under [Add On].  There can be no more than
  7. // five entries accepted by the File Manager.  For the entry, specify
  8. // the DLL and it's path, or place it in a directory like ...\nt\system.
  9.  
  10.  
  11. #include <windows.h>
  12. #include <WFEXT.h>
  13. #include <string.h>
  14. #include "my_fmext.h"
  15.  
  16. HWND       ghListBox;
  17. WORD       gwFilesDropped = 0;    // Total number of files dropped
  18. POINT       gpointDrop = {0,0};    // Point where the files were dropped
  19. static       HINSTANCE    hInstDll;
  20.  
  21.  
  22.  
  23. BOOL WINAPI DLLEntryPoint (HANDLE hDLL, DWORD dwReason, LPVOID lpReserved)
  24. {
  25.   hInstDll = hDLL;   //Save hinstance of DLL to be used for LoadMenu() later.
  26.   return TRUE;
  27. }
  28.  
  29. LONG WINAPI FMExtensionProc (HWND hWndFileMan, WORD wMsg, LONG lParam)
  30. {
  31.    WNDCLASS wc;
  32.    HWND        hMainWnd;
  33.    RECT     rectMain;
  34.    HMENU    hSubMenu;
  35.  
  36.    UINT     wDelta;
  37.  
  38.    switch (wMsg)
  39.     {
  40.     case FMEVENT_LOAD:
  41.       {
  42.       hSubMenu = LoadMenu (hInstDll, "My_FMExtentionMenu");
  43.       wDelta    = ((LPFMS_LOAD)lParam)->wMenuDelta;
  44.       ((LPFMS_LOAD)lParam)->dwSize = sizeof(FMS_LOAD);
  45.       strcpy(((LPFMS_LOAD)lParam)->szMenuName, "&Extention");
  46.       ((LPFMS_LOAD)lParam)->hMenu = hSubMenu;
  47.  
  48.         wc.style = NULL;
  49.         wc.lpfnWndProc = MainWndProc;
  50.         wc.cbClsExtra = 0;
  51.         wc.cbWndExtra = 0;
  52.     wc.hInstance = GetCurrentProcess();     //hinstance of FileManager.
  53.     wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
  54.         wc.hCursor = LoadCursor (NULL, IDC_ARROW);
  55.         wc.hbrBackground = GetStockObject (WHITE_BRUSH);
  56.         wc.lpszMenuName =  "DragDropMenu";
  57.         wc.lpszClassName = "DragDropWClass";
  58.  
  59.         if (!RegisterClass (&wc))
  60.         return (FALSE);
  61.     return (LONG) hSubMenu;
  62.       }
  63.  
  64.     case IDM_MYFMEXT:
  65.  
  66.       {
  67.       hMainWnd = CreateWindow ("DragDropWClass",
  68.                 "Drag and Drop Window for FileManager Extention",
  69.                             WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU
  70.                             | WS_MINIMIZEBOX,
  71.                             CW_USEDEFAULT,
  72.                             CW_USEDEFAULT,
  73.                 MAIN_WIDTH,
  74.                 MAIN_HEIGHT,
  75.                 CW_USEDEFAULT,
  76.                             NULL,
  77.                             NULL,
  78.                 GetCurrentProcess(),
  79.                             NULL);
  80.  
  81.       if (!hMainWnd)
  82.         return (FALSE);
  83.  
  84.       GetClientRect (hMainWnd, &rectMain);
  85.  
  86.       ghListBox = CreateWindow ("ListBox",
  87.                         NULL,
  88.                         WS_CHILD | WS_VSCROLL | LBS_NOINTEGRALHEIGHT
  89.                         | LBS_SORT | WS_VISIBLE,
  90.                         0,
  91.                         32,
  92.                         rectMain.right - rectMain.left,
  93.                         rectMain.bottom - rectMain.top - 32,
  94.                         hMainWnd,
  95.             NULL,
  96.             GetCurrentProcess(),
  97.             NULL);
  98.  
  99.       if (!ghListBox)
  100.     return (FALSE);
  101.  
  102.       // Register the the main window for Drag/Drop messages.
  103.       DragAcceptFiles (hMainWnd, TRUE);
  104.  
  105.       ShowWindow (hMainWnd, SW_SHOWNORMAL);
  106.       UpdateWindow (hMainWnd);
  107.       return (0);
  108.       }
  109.  
  110.     default:
  111.       {
  112.     return (0);
  113.       }
  114.     }
  115.  
  116.    return TRUE;
  117. }
  118.  
  119.  
  120. //**************************************************************************
  121. //
  122. //  FUNCTION: MainWndProc()
  123. //
  124. //  PURPOSE:
  125. //
  126. //  This function handles messages belonging to the main window.
  127. //  It also handles and processes Drag/Drop messages.
  128. //
  129. //**************************************************************************
  130.  
  131. long FAR PASCAL MainWndProc (HWND hWnd,   UINT message,
  132.                              WPARAM wParam, LPARAM lParam)
  133. {
  134.     HANDLE  hFilesInfo;
  135.     WORD    wIndex;
  136.     char    szFileName [FILE_NAME_LENGTH];
  137.  
  138.     switch (message)
  139.     {
  140.         case WM_DROPFILES:
  141.             hFilesInfo = (HANDLE) wParam;
  142.  
  143.             // Retrieve the window coordinates of the mouse
  144.             // pointer when the drop was made
  145.             DragQueryPoint ((HANDLE) wParam, (LPPOINT) &gpointDrop);
  146.  
  147.             // Get the total number of files dropped
  148.             gwFilesDropped = DragQueryFile (hFilesInfo,
  149.                                            (UINT)-1,
  150.                                            NULL,
  151.                                            0);
  152.  
  153.             // Retrieve each file name and add to the list box
  154.             for (wIndex=0; wIndex < gwFilesDropped; wIndex++)
  155.             {
  156.                 DragQueryFile (hFilesInfo,
  157.                                wIndex,
  158.                                (LPSTR) szFileName,
  159.                                FILE_NAME_LENGTH);
  160.  
  161.                 SendMessage (ghListBox,
  162.                              LB_ADDSTRING,
  163.                              0,
  164.                              (LONG) (LPSTR) szFileName);
  165.             } // for
  166.  
  167.             DragFinish (hFilesInfo);
  168.             break;
  169.  
  170.         default:
  171.             return (DefWindowProc (hWnd, message, wParam, lParam));
  172.  
  173.     } // switch (message)
  174.  
  175.     return (0);
  176.  
  177. } // MainWndProc()
  178.